<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>

<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>

<body class="nav-md"> 
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">

					<div class="clearfix"></div>

					<br />

				</div>
			</div>

			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left"></div>

						<div class="x_content">
						  <select class="btn btn-default dropdown-toggle" id="status" style="text-align: center;">
								<option value="4" <c:if test="${status == 4}">selected</c:if>> 全部</option>
								<option value="1" <c:if test="${status == 1}">selected</c:if>>通过</option>
								<option value="2" <c:if test="${status == 2}">selected</c:if>>待审核</option>
								<option value="3" <c:if test="${status == 3}">selected</c:if>>不通过</option>
						  </select>
						     店铺名: <input type="text" name="shopname" id="shopname"
								value="${shopname}" />
							<button type="submit" class="btn btn-default"
								onclick="selectOEM(1)">搜索</button>
						</div>
					</div>

					<div class="x_panel">

						<div class="x_content">

							<table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>店铺名</th>
										<th>店铺LOGO</th>
										<th>店铺背景</th>
										<th>店铺简介</th>
										<th>店铺地址</th>
										<th>联系人</th>
										<th>联系电话</th>
										<th>精选店铺</th>
										<th>精选操作</th>
										<th>审核进度</th>
										<th>审核时间</th>
										<th>店铺状态</th>
										<th>审核操作</th>
										<th>前十状态</th>
										<th>前十操作</th>
									</tr>
								</thead>

								<tbody>
									<c:forEach items="${selfShops}" var="s" varStatus="z">
										<tr>
											<td>${s.shopname}</td>
											<td><img src="${s.shoplogo}" alt="图片未读取"  style="width: 100px;height: 100px"/></td>
											<td><img src="${s.shopbg}" alt="图片未读取" style="width: 100px;height: 100px"/></td>
											<td>${s.introduction}</td>
											<td>${s.address}</td>
											<td>${s.contacts}</td>
											<td>${s.phonenum}</td>
											<td><c:if test="${s.ischoice == 0}">否</c:if>
											    <c:if test="${s.ischoice == 1}">是</c:if></td>
											<td><div class="input-group-btn">
													<button type="button"
														class="btn btn-default dropdown-toggle"
														data-toggle="dropdown" aria-expanded="false">
														是否精选 <span class="caret"></span>
													</button>
													<ul class="dropdown-menu dropdown-menu-right" role="menu">
														<li><a href="javascript:" type="submit"
                                                               onclick="upIsChoice('${s.id}','0')">否</a></li>
														<li><a href="javascript:" type="submit"
                                                               onclick="upIsChoice('${s.id}','1')">是</a></li>
													</ul>
												</div>
											</td>
											<td><c:if test="${s.isopen == 1}">通过</c:if>
											    <c:if test="${s.isopen == 2}">待审核</c:if>
											    <c:if test="${s.isopen == 3}">不通过</c:if></td>
											<td><fmt:formatDate value="${s.respondtime}" type="date"
													pattern="yyyy-MM-dd" />
											<td><c:if test="${s.datastatus == 0}">冻结</c:if>
											    <c:if test="${s.datastatus == 1}">正常</c:if></td>
											<td><div class="input-group-btn">
											  <c:if test='${s.isopen != 1}'>
													<button type="button"
														class="btn btn-default dropdown-toggle"
														data-toggle="dropdown" aria-expanded="false">
														是否通过 <span class="caret"></span>
													</button></c:if>
											  <c:if test='${s.isopen == 1}'>
													<button type="button"
														class="btn btn-default dropdown-toggle"
														data-toggle="dropdown" aria-expanded="false">
														是否冻结 <span class="caret"></span>
													</button></c:if>
													<ul class="dropdown-menu dropdown-menu-right" role="menu">
													    <c:if test='${s.isopen != 1}'>
														<li><a href="javascript:" type="submit"
                                                               onclick="upIsOpen('${s.id}','1')">通过</a></li>
														<li><a href="javascript:" type="submit"
                                                               onclick="upIsOpen('${s.id}','3')">不通过</a></li>
														</c:if>
														<c:if test='${s.isopen == 1}'>
														<li><a href="javascript:" type="submit"
                                                               onclick="upDataStatus('${s.id}','0')">冻结</a></li>
														<li><a href="javascript:" type="submit"
                                                               onclick="upDataStatus('${s.id}','1')">解冻</a></li>
														</c:if>
													</ul>
												</div>
											</td>
											<td><c:if test="${s.sort == true}">是</c:if>
												<c:if test="${s.sort == false}">否</c:if></td>
											<td><div class="input-group-btn">
												<button type="button"
														class="btn btn-default dropdown-toggle"
														data-toggle="dropdown" aria-expanded="false">
													是否前十 <span class="caret"></span>
												</button>
												<ul class="dropdown-menu dropdown-menu-right" role="menu">
													<li><a href="javascript:" type="submit"
                                                           onclick="upSort('${s.id}','false')">否</a></li>
													<li><a href="javascript:" type="submit"
                                                           onclick="upSort('${s.id}','true')">是</a></li>
												</ul>
											</div>
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
					<div class="clearfix"></div>
					<br />
				</div>
				<div style="width: 100%; text-align: center;">
					<div id='page'></div>
				</div>
			</div>
			<!-- /page content -->


			<script>
				/**
				 * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
				 */
				pageUtil.initPage('page', {
					totalCount : '${totlenum}', //总页数，一般从回调函数中获取。如果没有数据则默认为1页
					curPage : '${curPage}', //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
					showCount : 9, //分页栏显示的数量
					pageSizeList : [ 10 ], //自定义分页数，默认[5,10,15,20,50]
					defaultPageSize : 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
					isJump : true, //是否包含跳转功能，默认false
					isPageNum : true, //是否显示分页下拉选择，默认false
					isPN : true, //是否显示上一页和下一面，默认true
					isFL : true, //是否显示首页和末页，默认true
					jump : function(curPage, pageSize) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
						selectOEM(curPage);
					},
				});
			</script>

		</div>
	</div>
	
	<script type="text/javascript">
		function selectOEM(curPage) {
			var shopname = $("#shopname").val();
			var status = $("#status").find("option:selected").val();
			location.href = "selectSelfShopStore?curPage=" + curPage +
			        "&shopname=" + shopname +
			        "&status=" + status;
		}
		
		// ajax 对象
		function ajaxObject() {
			var xmlHttp;
			try {
				// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				// Internet Explorer
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
						alert("您的浏览器不支持AJAX！");
						return false;
					}
				}
			}
			return xmlHttp;
		}
		
		function upIsOpen(id, isopen) {
			var ajax = ajaxObject();
			ajax.open("post", "updateSelfShop?isopen=" + isopen +
				"&id=" + id , false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("审核完成");
							selectOEM(${curPage});
						} else {
							//创建失败
							alert(result);
						}
					} else if (ajax.status == 0) {
						//请求失败
						alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
					}else {
					//请求失败
					alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
				}
				} else {
				}
			};
			ajax.send();
	
		}
		
		function upDataStatus(id, datastatus) {
			var ajax = ajaxObject();
			ajax.open("post", "updateSelfShop?datastatus=" + datastatus +
				"&id=" + id , false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("审核状态修改成功");
							selectOEM(${curPage});
						} else {
							//创建失败
							alert(result);
						}
					} else if (ajax.status == 0) {
						//请求失败
						alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
					}else {
					//请求失败
					alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
				}
				} else {
				}
			};
			ajax.send();
	
		}
		function upIsChoice(id, ischoice) {
			var ajax = ajaxObject();
			ajax.open("post", "updateSelfShop?ischoice=" + ischoice +
				"&id=" + id , false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("精选状态修改成功");
							selectOEM(${curPage});
						} else {
							//创建失败
							alert(result);
						}
					} else if (ajax.status == 0) {
						//请求失败
						alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
					}else {
					//请求失败
					alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
				}
				} else {
				}
			};
			ajax.send();
	
		}

        function upSort(id, sort) {
            var ajax = ajaxObject();
            ajax.open("post", "updateSelfShop?falg=1&sort=" + sort +
                "&id=" + id , false);
            ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.onreadystatechange = function() {
                if (ajax.readyState == 4) {
                    if (ajax.status == 200) {
                        var result = ajax.responseText;
                        if (result == "success") {
                            //请求成功
                            alert("前十状态修改成功");
                            selectOEM(${curPage});
                        } else if (result == "success2") {
                            //创建失败
                            alert("前十已达上限");
                        } else {
                            //创建失败
                            alert(result);
                        }
                    } else if (ajax.status == 0) {
                        //请求失败
                        alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
                    }else {
                        //请求失败
                        alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
                    }
                } else {
                }
            };
            ajax.send();

        }
	</script>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- layui -->
	<script src="<%=basePath%>vendors/layui/layui.js"></script>

</body>
</html>